<?php

session_start(); 
$username=$_POST['cuid'];
$cuid=$_SESSION['username'];
//$cuid='gip2103';
//$username='gek1123';
$mesg='Hi, I want to connect with you!';
$accepted='No';

$conn = oci_connect("gaurav", "gaurav", "xe"); 

//echo 'Username'.$cuid.'CUID'.$username;

$query = "INSERT INTO Connects(friend1,friend2,msg,accepted) VALUES(:cuid,:username,:mesg,:accepted)";

//echo 'Message'.$cuid.$password1.$fname.$mname.$lname.$address1.$address2.$city.$state.$country.$zipcode.$cellnumber.$sex.$deptid.$role;

$bindargs = array();
array_push($bindargs, array('CUID', $cuid, -1));
array_push($bindargs, array('USERNAME', $username, -1));
array_push($bindargs, array('MESG', $mesg, -1));
array_push($bindargs, array('ACCEPTED', $accepted, -1));


$r = db_execute_statement($conn, $query, $bindargs);

?><script language='javascript'>alert('Add Request has been sent!');</script><?php
header('Location: /StudentHomePage.php');

function db_execute_statement($conn, $statement, $bindvars = array())
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }
    // Bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value 
    $$b[0] = $b[1];
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]);
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }

  $r = oci_execute($stid);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
  return($r);
}
?>